<?php

class AlumnosController extends Controller
{
	public $layout='//layouts/templete';
	public function actionIndex()
	{
		$tipo=Yii::app()->user->getState('id_tipo');
		$id_usuario=Yii::app()->user->getState('id_usuario');
		if($tipo==='ADMIN' && $id_usuario>0)
		{
		 	
			$rows=UsuariosExternos::model()->getTotalAlumnos();
			foreach ($rows as $row) 
			{
				$total=$row['total'];
			}
			$pages=new CPagination($total);
			$pages->pageSize=10;
			
			$model=UsuariosExternos::model()->getAlumnosNoExiste($pages->limit,$pages->offset);
			$this->render('index',array(
                        'model'=>$model,
                        'pages' => $pages

                        
                ));

		}
		else
		{
			$this->redirect(array('site/index'));
		}
	}
	public function actionNuevo($id)
	{	

		$tipo=Yii::app()->user->getState('id_tipo');
		$id_usuario=Yii::app()->user->getState('id_usuario');
		if($tipo==='ADMIN' && $id_usuario>0)
		{

			$model=UsuariosExternos::model()->findByPk($id);
			$modelAlumnos=new Alumnos();
			$modelAlumnos->id_alumno=$model->id_usuario;
			$modelAlumnos->seguro=null;
			$modelAlumnos->id_carrera=0;
			$modelAlumnos->status=1;
			$modelAlumnos->nombres=$model->nombres;
			$modelAlumnos->apellidop=$model->apellidop;
			$modelAlumnos->apellidom=$model->apellidom;
			$modelAlumnos->matricula=$model->matricula;

			$modeloCreado=new Alumnos();

			if(isset($_POST['Alumnos']))
			{
				
				$modelAlumnos->attributes=$_POST['Alumnos'];
        		if($modelAlumnos->validate())
        		{
        			$modelAlumnos->save();
        			$this->redirect(array('index'));
				}
			}
			$this->render('formAlumnos',array(
                        'model'=>$modelAlumnos));
                        
          }
          else{
          	$this->redirect(array('site/index'));
          }              
                
	}
	public function actionInscritos()
	{
		$tipo=Yii::app()->user->getState('id_tipo');
		$id_usuario=Yii::app()->user->getState('id_usuario');
		if($tipo==='ADMIN' && $id_usuario>0)
		{


			$rows=Alumnos::model()->getTotalAlumnosInscritos();
			
			if(!($rows===null))
			{
			 foreach ($rows as $row) 
			{
				$total=$row['total'];
			}
			//echo ($total);
			$pages=new CPagination($total);
			$pages->pageSize=10;
			
			$model=Alumnos::model()->getAlumnosInscritos($pages->limit,$pages->offset);

			$condicion= array('activo' =>1 );
			$ciclo=CiclosEScolares::model()->findByAttributes($condicion);

			$this->render('lst_inscritos',array(
                        'model'=>$model,
                        'pages' => $pages,
                        'ciclo'=>$ciclo
                        
                ));	
			}
			else
			{
				$this->render('lst_inscritos',array(
                        'model'=>null,
                        'pages' => null,
                        'ciclo'=>null
                ));	
				
	
			}

			
			
	

			//$this->render('lst_inscritos', array('model' =>$model , 'pages' => $pages));
            
                        
          }
          else{
          	$this->redirect(array('site/index'));
          }   
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}